import 'package:app_core/app_core.dart';
import 'package:flutter/material.dart';

/// 空状态组件 - 可复用的空状态UI
class EmptyStateWidget extends StatelessWidget {
  /// 空状态图标
  final IconData? icon;

  /// 空状态标题
  final String? title;

  /// 空状态描述
  final String? description;

  /// 操作按钮文本
  final String? actionText;

  /// 操作按钮回调
  final VoidCallback? onAction;

  /// 自定义图标颜色
  final Color? iconColor;

  /// 自定义文字颜色
  final Color? textColor;

  /// 图标大小
  final double? iconSize;

  /// 是否显示操作按钮
  final bool showAction;

  /// 自定义内容
  final Widget? customContent;

  const EmptyStateWidget({
    super.key,
    this.icon,
    this.title,
    this.description,
    this.actionText,
    this.onAction,
    this.iconColor,
    this.textColor,
    this.iconSize = 180,
    this.showAction = true,
    this.customContent,
  });

  /// 默认空状态 - 通用
  const EmptyStateWidget.defaultEmpty({super.key, this.actionText, this.onAction, this.showAction = true, this.iconSize = 80})
    : icon = Icons.inbox_outlined,
      title = '暂无数据',
      description = '当前没有任何数据可以显示',
      iconColor = Colors.grey,
      textColor = Colors.grey,
      customContent = null;

  /// 列表空状态
  const EmptyStateWidget.listEmpty({super.key, this.actionText, this.onAction, this.showAction = true, this.iconSize = 80})
    : icon = Icons.list_alt_outlined,
      title = '暂无列表数据',
      description = '当前列表为空，点击下方按钮添加数据',
      iconColor = Colors.grey,
      textColor = Colors.grey,
      customContent = null;

  /// 搜索结果空状态
  const EmptyStateWidget.searchEmpty({super.key, this.actionText, this.onAction, this.showAction = true, this.iconSize = 80})
    : icon = Icons.search_off_outlined,
      title = '未找到相关内容',
      description = '请尝试其他关键词或调整搜索条件',
      iconColor = Colors.grey,
      textColor = Colors.grey,
      customContent = null;

  /// 网络错误空状态
  const EmptyStateWidget.networkError({super.key, this.actionText, this.onAction, this.showAction = true, this.iconSize = 80})
    : icon = Icons.wifi_off_outlined,
      title = '网络连接失败',
      description = '请检查网络连接后重试',
      iconColor = Colors.orange,
      textColor = Colors.orange,
      customContent = null;

  /// 权限错误空状态
  const EmptyStateWidget.permissionError({super.key, this.actionText, this.onAction, this.showAction = true, this.iconSize = 80})
    : icon = Icons.lock_outline,
      title = '权限不足',
      description = '需要相关权限才能访问此功能',
      iconColor = Colors.red,
      textColor = Colors.red,
      customContent = null;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 24),
          child: Center(
            child: customContent ?? _buildDefaultContent(),
          ),
    );
  }
  //
  // @override
  // Widget build(BuildContext context) {
  //   final screenHeight = MediaQuery.of(context).size.height;
  //   final appBarHeight = AppBar().preferredSize.height;
  //   final statusBarHeight = MediaQuery.of(context).padding.top;
  //   final availableHeight = screenHeight - appBarHeight - statusBarHeight;
  //
  //   return Container(
  //     height: availableHeight - 150,
  //
  //     child: Center(
  //       child: customContent ?? _buildDefaultContent(),
  //     ),
  //   );
  // }

  Widget _buildDefaultContent() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        if (icon != null) Icon(icon, size: iconSize, color: iconColor ?? Colors.grey),

        const SizedBox(height: 12),

        if (title != null)
          Text(title!, style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: textColor ?? Colors.grey), textAlign: TextAlign.center),

        const SizedBox(height: 8),

        if (description != null) Text(description!, style: TextStyle(fontSize: 14, color: textColor ?? Colors.grey), textAlign: TextAlign.center),

        if (showAction && actionText != null && onAction != null) ...[
          const SizedBox(height: 24),
          ElevatedButton(onPressed: onAction, child: Text(actionText!)),
        ],
      ],
    );
  }
}
